package com.huxuesong.prcc.util.submail;

import com.huxuesong.prcc.util.submail.config.AppConfig;
import com.huxuesong.prcc.util.submail.lib.MAILSend;
import com.huxuesong.prcc.util.submail.lib.MAILXSend;
import com.huxuesong.prcc.util.submail.lib.MessageSend;
import com.huxuesong.prcc.util.submail.utils.ConfigLoader;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class SubMailSender {
    @Autowired
    private ConfigLoader configLoader;

    public void sendMsgAuthCode(String telephone,String content){
        AppConfig config = configLoader.load(ConfigLoader.ConfigType.Message);
        MessageSend submail = new MessageSend(config);
        submail.addTo(telephone);
        submail.addContent(content);
        submail.send();
    }

    public void sendMailAuthCode(String toAddress,String title,String content){
        AppConfig config =  configLoader.load(ConfigLoader.ConfigType.Mail);
        MAILSend submail = new MAILSend(config);
//
        submail.addTo(toAddress,"");
        submail.setSender("admin@prccweb.com","PRCC");
//        submail.setReply("service@submail.cn");
        submail.setSubject(title);
        submail.setText(content);
//        submail.addAttachment("D:\\Program Files\\eclipse-php-luna-SR1-win32\\eclipse\\epl-v10.html");
//        submail.setHtml("test SDK html @var(name),@var(age) <a href=\"var://@link(test)\">testLink</a> <a href=\"var://@link(test2)\">testLink2</a>");
//        submail.addVar("name", "leo");
//        submail.addVar("age", "32");
//        submail.addLink("developer", "http://submail.cn/chs/developer");
//        submail.addLink("store", "http://submail.cn/chs/store");
//        submail.addHeaders("X-Accept", "zh-cn");
//        submail.addHeaders("X-Mailer", "leo App");
        submail.send();
    }

    /*
     *发送模板邮件
     */
    public void sendXMailAuthCode(String toAddress,String code){
        AppConfig config = configLoader.load(ConfigLoader.ConfigType.Mail);
        MAILXSend submail = new MAILXSend(config);
        submail.addTo(toAddress,"");
		submail.setSender("admin@prccweb.com","PRCC");
        submail.setProject("YuIUo");
        submail.addVar("code", code);
//        submail.addVar("age", "32");
//        submail.addLink("developer", "http://submail.cn/chs/developer");
//        submail.addLink("store", "http://submail.cn/chs/store");
//        submail.addHeaders("X-Accept", "zh-cn");
//        submail.addHeaders("X-Mailer", "leo App");
        submail.xsend();

    }
}
